	
	package converter;

	import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import dao.FuncionarioDAO;

import to.Funcionario;


	@FacesConverter(value = "converterFuncionario")
	public class ConverterFuncionario implements Converter {
		
		@Override

		public Object getAsObject(FacesContext context, UIComponent component, String value) {
			
			
			try {
				if (value != null && !value.equals("")) {
					FuncionarioDAO funcDAO = new FuncionarioDAO();
					return funcDAO.buscarFuncionarioPorCodigo((Integer.parseInt(value)));
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}

		@Override

		public String getAsString(FacesContext context, UIComponent component, Object value) {
			if (value instanceof Funcionario) {
				Funcionario func = (Funcionario) value;
				return String.valueOf(func.getId());
			}
			return "";
		}
	}

